var Index = require('../app/controllers/index')
var User = require('../app/controllers/user')
var Movie = require('../app/controllers/movie')
var Comment = require('../app/controllers/comment')
var Category = require('../app/controllers/category')


module.exports=function(app){
//pre handle user 这个时候出现了之前的问题，怎么请求都没响应，而且还不报错。把这一段注销掉就好了，说明问题在这里，得改改
app.use(function(req,res,next){
	var _user=req.session.user
	if (_user) {
		app.locals.user = _user
		next()//进入下一个路由，还是不太理解next
	}else{
		next()//加了else就好了，但不排除以后会不会有问题；说明老师讲的也不一定都对	
	}
})


//index 
app.get('/',Index.index)

//user
app.post('/user/signup',User.signup)
app.post('/user/signin',User.signin)
app.get('/logout',User.logout)
app.get('/signin',User.showSignin )
app.get('/signup',User.showSignup )
app.get('/admin/user/userlist',User.signinRequired,User.adminRequired,User.userlist)//通过中间件做访问权限管理

//movie
/*app.get('/movie/:id',Movie.detail)
app.get('/admin/movie/new',User.signinRequired,User.adminRequired,Movie.new)
app.get('/admin/movie/update/:id',User.signinRequired,User.adminRequired,Movie.update)
app.post('/admin/movie',User.signinRequired,User.adminRequired, Movie.save)
app.get('/admin/movie/list',User.signinRequired,User.adminRequired,Movie.movielist)
app.delete('/admin/movie/list',User.signinRequired,User.adminRequired,Movie.del)//这里路由路径是一样的，删除还是有点特别的
*/
app.get('/movie/:id',Movie.detail)
app.get('/admin/movie/new',Movie.new)
app.get('/admin/movie/update/:id',Movie.update)
app.post('/admin/movie',Movie.savePoster, Movie.save)
app.get('/admin/movie/list',Movie.movielist)
app.delete('/admin/movie/list',Movie.del)

//comment
app.post ('/user/comment',User.signinRequired,Comment.save)

//category
app.get('/admin/category/new',Category.new)
app.post('/admin/category', Category.save)
app.get('/admin/category/list',Category.categorylist)

//results
app.get('/results',Index.search)



}